// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using System;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Elastic.Clients.Elasticsearch.Serverless.Core;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;

namespace Elastic.Clients.Elasticsearch.Serverless.Ml;

[JsonConverter(typeof(TokenizationTruncateConverter))]
public enum TokenizationTruncate
{
	[EnumMember(Value = "second")]
	Second,
	[EnumMember(Value = "none")]
	None,
	[EnumMember(Value = "first")]
	First
}

internal sealed class TokenizationTruncateConverter : JsonConverter<TokenizationTruncate>
{
	public override TokenizationTruncate Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		var enumString = reader.GetString();
		switch (enumString)
		{
			case "second":
				return TokenizationTruncate.Second;
			case "none":
				return TokenizationTruncate.None;
			case "first":
				return TokenizationTruncate.First;
		}

		ThrowHelper.ThrowJsonException(); return default;
	}

	public override void Write(Utf8JsonWriter writer, TokenizationTruncate value, JsonSerializerOptions options)
	{
		switch (value)
		{
			case TokenizationTruncate.Second:
				writer.WriteStringValue("second");
				return;
			case TokenizationTruncate.None:
				writer.WriteStringValue("none");
				return;
			case TokenizationTruncate.First:
				writer.WriteStringValue("first");
				return;
		}

		writer.WriteNullValue();
	}
}